Victor Image Processing Library -- Sample Code

These simple examples show how easy it is to load and display images with the Victor Library. The Windows and Dos versions of the library have identical function calls.

In all of the examples you will see references to Image Descriptors. The Image Descriptor is the data structure Victor uses to hold information about the image and the palette. The address of the Image Descriptor is an argument to every function call. Your application can handle any number of images at the same time.

Victor for Windows or 32-bit Windows
Victor for Windows -- Visual Basic Sample
Victor for Dos


Victor for Windows or 32-bit Windows

Victor for Windows and Victor for 32-bit Windows are DLLs that can be called by any 16- or 32-bit language, respectively, that supports DLLs

Here is some sample code using Victor to load, sharpen, and display a grayscale 640 x 480 8-bit TIFF image. To allocate the image buffer and load the image . . .

     imgdes image;             /* Image descriptor */
     int width = 640, length = 480;
     int bitsperpixel = 8;     /* Bits per pixel */

     allocimage(&image, width, length, bitsperpixel);
     loadtif("SPIDER.TIF", &image);

If the image size and type are unknown we can use the tiffinfo function to gain the necessary information.

     imgdes image;         /* Image descriptor */
     TiffData tdata;       /* TIFF information */
     int width, length;
     int bitsperpixel;
     
     tiffinfo("SPIDER.TIF"), &tdata);
     width = tdata.width;
     length = tdata.length;
     bitsperpixel = tdata.vbitcount;
     allocimage(&image, width, length, bitsperpixel);
     loadtif("SPIDER.TIF", &image);

The allocimage function allocates space in global memory for the the image as a Device Independent Bitmap (DIB) with header, palette, and image data.

Next, apply image processing to enhance the grayscale image when displayed. To gently sharpen and balance the contrast of the image . . .

     sharpengentle(&image, &image);
     histoequalize(&image, &image);

To display the image in a window we use the following code.

     HDC hDC;
     PAINTSTRUCT ps;
     HPALETTE hpal;
          .
          .
          .
     case WM_PAINT:
          hDC = BeginPaint(hWnd, &ps);
          viewimage(hWnd, hDC,&hpal,0,0,&image);
          EndPaint(hWnd,&ps);

The viewimage function displays the image, sets, and realizes the colorpalette.

To release the memory before exiting the program . . .

     freeimage(&image);


Victor for Windows -- Visual Basic Sample Code

In this example we will load and display an 8-bit BMP image. First, in the global file we place the Image Descriptor definition and the declarations for the functions that we will call.

     ' Image descriptor Victor uses to hold information about the image

     Type imgdes
        ibuff As Long
        stx As Integer
        sty As Integer
        endx As Integer
        endy As Integer
        buffwidth As Integer
        palette As Long
        colors As Integer
        imgtype As Integer
        bmh As Long
     End Type

     Declare Function allocimage Lib "VIC.DLL" (image As imgdes, ByVal wid As Integer, ByVal leng As Integer, ByVal BPPixel As Integer) As Integer
     Declare Function bmpinfo Lib "VIC.DLL" (ByVal Fname As String, bdat As BITMAPINFOHEADER) As Integer
     Declare Sub freeimage Lib "VIC.DLL" (image As imgdes)
     Declare Function loadbmp Lib "VIC.DLL" (ByVal Fname As String, image As imgdes) As Integer
     Declare Function viewimage Lib "VIC.DLL" (ByVal hWnd As Integer, ByVal hDC As Integer, hpal As Integer, ByVal pos As Integer, ByVal ypos As Integer, image As imgdes) As Integer
Define the image descriptor and file name variables.

     'Global variables

     Global Fname As String
     Global vimage As imgdes
Then add the Victor bmpinfo, allocimage, and loadbmp functions to the File Open Dialog box.

     Sub IDM_OPEN_Click (Index As Integer)
     ' File Open Dialog box to load a BMP file

     Dim width As Integer
     Dim length As Integer
     Dim bitsperpixel As Integer
     Dim rcode As Integer
     Dim bmpdata As BITMAPINFOHEADER

     Cancel = False
     OpenDlg.Show 1      'Modal dialog box to get filename
     If Cancel = False Then
         ' Get information about the file to load
         rcode = bmpinfo(Fname, bmpdata)
         width = bmpdata.biWidth;
         length = bmpdata.biHeight;
         bitsperpixel = bmpdata.biBitcount
         ' Allocate new buffer to hold image
         rcode = allocimage(vimage, width, length, bitsperpixel)
         rcode = loadbmp(Fname, vimage)
         backcolor = &HFFFFFF    ' Erase previous image

         form_paint ' Repaint the screen to display image

         ' Handle any errors
         If rcode <> NO_ERROR Then
              error_handler rcode, Fname
         End If
     End If
     End Sub
And the viewimage function is added to the Form Paint subroutine.

     Sub form_paint ()
     Dim hpal As Integer, rcode As Integer

     rcode = viewimage(hWnd, hDC, hpal, 0, 0, vimage)
    
     End Sub

Victor for Dos

Victor for Dos is a linkable library compatible with Borland and Microsoft C/C++ compilers.

Here is some sample code using Victor for Dos to load, display, and save a 640 x 480 8-bit palette color image. To allocate space for an image . . .

     imgdes image;          /* image descriptor */
     int width = 640, length = 480;

     vmallocimage(&image, width, length, 8, EM_XM_CM_FM_);

The vmallocimage function allocates space for the image and palette data. The constant EM_XM_CM_FM_ sets the strategy for the allocation. In this example vmallocimage seeks space for the buffer first in expanded, then extended, then conventional, and finally in virtual memory.

The image and palette buffers are ready to receive an image using a file load function. To load a 256-color PCX file . . .

     loadpcx("SPIDER.PCX", &image);

The loadpcx function loads the image with its color palette. After the image is loaded, it is ready for processing, display, or saving to another file. To display the image on a Super VGA 640 x 480 256-color display adapter . . .

     int viewmode = V640x480x256;  /* Defined constant */

     setvideomode(videomode);
     viewimageinit(viewmode, &image);
     /*  Display image in the upper left
         corner of the screen */
     viewimage(0, 0, &image);

The viewimageinit function sets the display colors and initializes variables for the viewimage function. The viewimage function displays the image where requested without disturbing the rest of the screen.

Now that we have displayed the image, let's save it as a GIF file.

     savegif("SPIDER.GIF", &image);

To release the memory before exiting the program . . .

     freeimage(&image);


Victor Image Processing Library - Welcome
What's New with Victor
Product Summary
Function Summary
Sample Code


Copyright © 1995 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.